package Review;


public class Test13 {

	public static void main(String[] args) {
		ListNode p1=new ListNode(1);		
		ListNode p2=new ListNode(2);
		p1.next=p2;
		ListNode p3=new ListNode(3);
		p2.next=p3;
		ListNode p4=new ListNode(4);
		p3.next=p4;
		p4.next=null;
		ListNode p0=p1;
		while(p0!=null)
		{
			System.out.println(p0.value);
			p0=p0.next;
		}
		deleteNode(p1,p2);
		ListNode po=p1;
		while(po!=null)
		{
			System.out.println(po.value);
			po=po.next;
		}
	}
    public static void deleteNode(ListNode head,ListNode deleted){
    	if(head==null||deleted==null){
    		return;
    	}
    	if(deleted==head&&head.next==null){
    		head=null;
    		return;
    	}
    	if(deleted.next!=null){
    		deleted.value=deleted.next.value;
    		deleted.next=deleted.next.next;
    		return;
    	}
    	if(deleted.next==null){
    		ListNode p = head;
    		while(p.next!=deleted){
    			p=p.next;
    		}
    		p.next=null;
    		return;
    	}
    	
    }
}
